package cheme.ProcessEditor.Parts;

import java.beans.PropertyChangeEvent;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;

import cheme.ProcessEditor.Figures.ConsoleViewFig;
import cheme.ProcessEditor.Figures.SolvabilityStatusFig;
import cheme.ProcessEditor.Figures.TooltipFig;
import cheme.ProcessEditor.Parts.Equations.PolicyEquationsLayout;
import cheme.ProcessModel.SolvabilityStatus;
import cheme.ProcessModel.TooltipModel;

public class ToolTipPart extends PropertyAwarePart implements INonResizablePart
{

	@Override
	protected IFigure createFigure() 
	{		
		
		TooltipFig fig = new TooltipFig();
		fig.setVisibility(false);
		fig.setMessage("");
		
		return fig;
	}
	
	@Override
	public TooltipFig getFigure()
	{
		return (TooltipFig)super.getFigure();
	}
	

	@Override
	protected void createEditPolicies()
	{
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new PolicyEquationsLayout());
		
	}
	
	public void refreshVisuals()
	{
		Point loc = ((TooltipModel) getModel()).getLocation();
		Rectangle constraint = new Rectangle(loc.x +12, loc.y + 3, 200, 150);
	    ((GraphicalEditPart)getParent()).setLayoutConstraint(this, getFigure(), constraint);
		
	}
	protected void handleVisibilityChange (PropertyChangeEvent evt)
	{
		TooltipFig fig = (TooltipFig)super.getFigure();
		boolean bvisible = ((TooltipModel) getModel()).getVisibility();
		fig.setVisibility(bvisible);
		//super.handleVisibilityChange(evt);
	}
	
	protected void handleTextChange(PropertyChangeEvent evt)
	{
		TooltipFig fig = (TooltipFig)super.getFigure();
		boolean bvisible = ((TooltipModel) getModel()).getVisibility();
		fig.setVisibility(bvisible);
		
		String message = ((TooltipModel) getModel()).getMessage();
		fig.setMessage(message);
		
		
	}
	
	protected void handleBoundsChange(PropertyChangeEvent evt)
	{
		TooltipFig fig = (TooltipFig)super.getFigure();
		Point p = ((TooltipModel) getModel()).getLocation();
		fig.setLocation(p);	
		refreshVisuals();
		super.handleBoundsChange(evt);
	}
	
	

}
